#Boa:Frame:Frame1

import wx,re,math
GlobalStr=""
Data1=""
Data2=""
Flag=1
YunSuan=""
Flag_YunSuan=0

def create(parent):
    return Frame1(parent)
    
[wxID_FRAME1, wxID_FRAME1BUTTON0, wxID_FRAME1BUTTON1, wxID_FRAME1BUTTON2, 
 wxID_FRAME1BUTTON3, wxID_FRAME1BUTTON4, wxID_FRAME1BUTTON5, 
 wxID_FRAME1BUTTON6, wxID_FRAME1BUTTON7, wxID_FRAME1BUTTON8, 
 wxID_FRAME1BUTTON9, wxID_FRAME1BUTTONADD, wxID_FRAME1BUTTONBACKSPACE, 
 wxID_FRAME1BUTTONC, wxID_FRAME1BUTTONCE, wxID_FRAME1BUTTONDAO, 
 wxID_FRAME1BUTTONDEC, wxID_FRAME1BUTTONDIV, wxID_FRAME1BUTTONEQU, 
 wxID_FRAME1BUTTONPERCENT, wxID_FRAME1BUTTONPOSNAG, wxID_FRAME1BUTTONPOT, 
 wxID_FRAME1BUTTONSQRT, wxID_FRAME1BUTTONX, wxID_FRAME1PANEL1, 
 wxID_FRAME1TEXTCTRL1, 
] = [wx.NewId() for _init_ctrls in range(26)]

class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(342, 224), size=wx.Size(335, 352),
              style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
        self.SetClientSize(wx.Size(327, 318))

        self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
              pos=wx.Point(0, 0), size=wx.Size(327, 318),
              style=wx.TAB_TRAVERSAL)
        self.panel1.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.NORMAL, False,
              u'Tahoma'))

        self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL1, name='textCtrl1',
              parent=self.panel1, pos=wx.Point(16, 16), size=wx.Size(288, 64),
              style=0, value=u'0')
        self.textCtrl1.SetFont(wx.Font(36, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))
        self.textCtrl1.SetToolTipString(u'')

        self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label=u'1',
              name='button1', parent=self.panel1, pos=wx.Point(16, 144),
              size=wx.Size(46, 30), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
              id=wxID_FRAME1BUTTON1)

        self.button2 = wx.Button(id=wxID_FRAME1BUTTON2, label=u'2',
              name='button2', parent=self.panel1, pos=wx.Point(76, 144),
              size=wx.Size(46, 30), style=0)
        self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button,
              id=wxID_FRAME1BUTTON2)

        self.button3 = wx.Button(id=wxID_FRAME1BUTTON3, label=u'3',
              name='button3', parent=self.panel1, pos=wx.Point(136, 144),
              size=wx.Size(46, 30), style=0)
        self.button3.Bind(wx.EVT_BUTTON, self.OnButton3Button,
              id=wxID_FRAME1BUTTON3)

        self.button4 = wx.Button(id=wxID_FRAME1BUTTON4, label=u'4',
              name=u'button4', parent=self.panel1, pos=wx.Point(16, 188),
              size=wx.Size(46, 30), style=0)
        self.button4.Bind(wx.EVT_BUTTON, self.OnButton4Button,
              id=wxID_FRAME1BUTTON4)

        self.button5 = wx.Button(id=wxID_FRAME1BUTTON5, label=u'5',
              name='button5', parent=self.panel1, pos=wx.Point(76, 188),
              size=wx.Size(40, 30), style=0)
        self.button5.Bind(wx.EVT_BUTTON, self.OnButton5Button,
              id=wxID_FRAME1BUTTON5)

        self.button6 = wx.Button(id=wxID_FRAME1BUTTON6, label=u'6',
              name='button6', parent=self.panel1, pos=wx.Point(136, 188),
              size=wx.Size(46, 30), style=0)
        self.button6.Bind(wx.EVT_BUTTON, self.OnButton6Button,
              id=wxID_FRAME1BUTTON6)

        self.button7 = wx.Button(id=wxID_FRAME1BUTTON7, label=u'7',
              name='button7', parent=self.panel1, pos=wx.Point(16, 232),
              size=wx.Size(46, 30), style=0)
        self.button7.Bind(wx.EVT_BUTTON, self.OnButton7Button,
              id=wxID_FRAME1BUTTON7)

        self.button8 = wx.Button(id=wxID_FRAME1BUTTON8, label=u'8',
              name='button8', parent=self.panel1, pos=wx.Point(76, 232),
              size=wx.Size(46, 30), style=0)
        self.button8.Bind(wx.EVT_BUTTON, self.OnButton8Button,
              id=wxID_FRAME1BUTTON8)

        self.button9 = wx.Button(id=wxID_FRAME1BUTTON9, label=u'9',
              name='button9', parent=self.panel1, pos=wx.Point(136, 232),
              size=wx.Size(46, 30), style=0)
        self.button9.Bind(wx.EVT_BUTTON, self.OnButton9Button,
              id=wxID_FRAME1BUTTON9)

        self.button0 = wx.Button(id=wxID_FRAME1BUTTON0, label=u'0',
              name=u'button0', parent=self.panel1, pos=wx.Point(16, 276),
              size=wx.Size(46, 30), style=0)
        self.button0.Bind(wx.EVT_BUTTON, self.OnButton0Button,
              id=wxID_FRAME1BUTTON0)

        self.buttonpot = wx.Button(id=wxID_FRAME1BUTTONPOT, label=u'.',
              name=u'buttonpot', parent=self.panel1, pos=wx.Point(136, 276),
              size=wx.Size(46, 30), style=0)
        self.buttonpot.SetFont(wx.Font(24, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))
        self.buttonpot.Bind(wx.EVT_BUTTON, self.OnButtonpotButton,
              id=wxID_FRAME1BUTTONPOT)

        self.buttonPosNag = wx.Button(id=wxID_FRAME1BUTTONPOSNAG, label=u'+/-',
              name=u'buttonPosNag', parent=self.panel1, pos=wx.Point(76, 276),
              size=wx.Size(46, 30), style=0)
        self.buttonPosNag.Bind(wx.EVT_BUTTON, self.OnButtonPosNagButton,
              id=wxID_FRAME1BUTTONPOSNAG)

        self.buttonX = wx.Button(id=wxID_FRAME1BUTTONX, label=u'*',
              name=u'buttonX', parent=self.panel1, pos=wx.Point(196, 144),
              size=wx.Size(46, 30), style=0)
        self.buttonX.SetForegroundColour(wx.Colour(255, 0, 0))
        self.buttonX.Bind(wx.EVT_BUTTON, self.OnButtonXButton,
              id=wxID_FRAME1BUTTONX)

        self.buttondiv = wx.Button(id=wxID_FRAME1BUTTONDIV, label=u'/',
              name=u'buttondiv', parent=self.panel1, pos=wx.Point(196, 188),
              size=wx.Size(46, 30), style=0)
        self.buttondiv.SetForegroundColour(wx.Colour(255, 0, 0))
        self.buttondiv.Bind(wx.EVT_BUTTON, self.OnButtondivButton,
              id=wxID_FRAME1BUTTONDIV)

        self.buttondec = wx.Button(id=wxID_FRAME1BUTTONDEC, label=u'-',
              name=u'buttondec', parent=self.panel1, pos=wx.Point(196, 232),
              size=wx.Size(46, 30), style=0)
        self.buttondec.SetForegroundColour(wx.Colour(255, 0, 0))
        self.buttondec.Bind(wx.EVT_BUTTON, self.OnButtondecButton,
              id=wxID_FRAME1BUTTONDEC)

        self.buttonadd = wx.Button(id=wxID_FRAME1BUTTONADD, label=u'+',
              name=u'buttonadd', parent=self.panel1, pos=wx.Point(196, 276),
              size=wx.Size(46, 30), style=0)
        self.buttonadd.SetForegroundColour(wx.Colour(255, 0, 0))
        self.buttonadd.Bind(wx.EVT_BUTTON, self.OnButtonaddButton,
              id=wxID_FRAME1BUTTONADD)

        self.buttonbackspace = wx.Button(id=wxID_FRAME1BUTTONBACKSPACE,
              label=u'BackSpace', name=u'buttonbackspace', parent=self.panel1,
              pos=wx.Point(16, 96), size=wx.Size(113, 36), style=0)
        self.buttonbackspace.SetForegroundColour(wx.Colour(255, 0, 0))
        self.buttonbackspace.Bind(wx.EVT_BUTTON, self.OnButtonbackspaceButton,
              id=wxID_FRAME1BUTTONBACKSPACE)

        self.buttonce = wx.Button(id=wxID_FRAME1BUTTONCE, label=u'CE',
              name=u'buttonce', parent=self.panel1, pos=wx.Point(152, 96),
              size=wx.Size(72, 36), style=0)
        self.buttonce.SetForegroundColour(wx.Colour(255, 0, 0))
        self.buttonce.Bind(wx.EVT_BUTTON, self.OnButtonceButton,
              id=wxID_FRAME1BUTTONCE)

        self.buttonc = wx.Button(id=wxID_FRAME1BUTTONC, label=u'C',
              name=u'buttonc', parent=self.panel1, pos=wx.Point(248, 96),
              size=wx.Size(56, 36), style=0)
        self.buttonc.SetForegroundColour(wx.Colour(255, 0, 0))
        self.buttonc.Bind(wx.EVT_BUTTON, self.OnButtoncButton,
              id=wxID_FRAME1BUTTONC)

        self.buttonsqrt = wx.Button(id=wxID_FRAME1BUTTONSQRT, label=u'Sqrt',
              name=u'buttonsqrt', parent=self.panel1, pos=wx.Point(260, 144),
              size=wx.Size(46, 30), style=0)
        self.buttonsqrt.Bind(wx.EVT_BUTTON, self.OnButtonsqrtButton,
              id=wxID_FRAME1BUTTONSQRT)

        self.buttonpercent = wx.Button(id=wxID_FRAME1BUTTONPERCENT, label=u'%',
              name=u'buttonpercent', parent=self.panel1, pos=wx.Point(260, 232),
              size=wx.Size(46, 30), style=0)
        self.buttonpercent.Bind(wx.EVT_BUTTON, self.OnButtonpercentButton,
              id=wxID_FRAME1BUTTONPERCENT)

        self.buttondao = wx.Button(id=wxID_FRAME1BUTTONDAO, label=u'1/X',
              name=u'buttondao', parent=self.panel1, pos=wx.Point(260, 188),
              size=wx.Size(46, 30), style=0)
        self.buttondao.Bind(wx.EVT_BUTTON, self.OnButtondaoButton,
              id=wxID_FRAME1BUTTONDAO)

        self.buttonequ = wx.Button(id=wxID_FRAME1BUTTONEQU, label=u'=',
              name=u'buttonequ', parent=self.panel1, pos=wx.Point(260, 276),
              size=wx.Size(46, 30), style=0)
        self.buttonequ.SetForegroundColour(wx.Colour(255, 0, 0))
        self.buttonequ.Bind(wx.EVT_BUTTON, self.OnButtonequButton,
              id=wxID_FRAME1BUTTONEQU)

    def __init__(self, parent):
        self._init_ctrls(parent)

    def OnButton1Button(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        GlobalStr="".join((GlobalStr,"1"))
        self.textCtrl1.SetValue(GlobalStr)
        if Flag:
            Data2=GlobalStr
        else:
            Data1=GlobalStr
        print ("Data1:%s;Data2:%s" %(Data1,Data2))        
    def OnButton2Button(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        GlobalStr="".join((GlobalStr,"2"))
        self.textCtrl1.SetValue(GlobalStr)
        if Flag:
            Data2=GlobalStr
        else:
            Data1=GlobalStr
        print ("Data1:%s;Data2:%s" %(Data1,Data2)) 
    def OnButton3Button(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        GlobalStr="".join((GlobalStr,"3"))
        self.textCtrl1.SetValue(GlobalStr)
        if Flag:
            Data2=GlobalStr
        else:
            Data1=GlobalStr
        print ("Data1:%s;Data2:%s" %(Data1,Data2)) 

    def OnButtonXButton(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        if Flag:
            Flag=0            
            
        #elif Flag_YunSuan :
        #    Flag=1 
        #    Data1=Data2
            #Data2=GlobalStr
        else :
            Flag=1
        YunSuan="*"       
        GlobalStr=""
        self.textCtrl1.SetValue("")
        print ("Data1:%s;Data2:%s" %(Data1,Data2))
        print 

    def OnButtonsqrtButton(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        if Flag:
            Flag=0
            Temp=int(Data2)
            
        #elif Flag_YunSuan :
        #    Flag=1 
        #    Data1=Data2
            #Data2=GlobalStr
        else :
            Flag=1
            Temp=int(Data1)
        #YunSuan="sqr"       
        GlobalStr=""
        
        Temp=math.sqrt(Temp)
        self.textCtrl1.SetValue(str(Temp))
        print ("Data1:%s;Data2:%s" %(Data1,Data2))
        print 

    def OnButton4Button(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        GlobalStr="".join((GlobalStr,"4"))
        self.textCtrl1.SetValue(GlobalStr)
        if Flag:
            Data2=GlobalStr
        else:
            Data1=GlobalStr
        print ("Data1:%s;Data2:%s" %(Data1,Data2)) 
    def OnButton5Button(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        GlobalStr="".join((GlobalStr,"5"))
        self.textCtrl1.SetValue(GlobalStr)
        if Flag:
            Data2=GlobalStr
        else:
            Data1=GlobalStr
        print ("Data1:%s;Data2:%s" %(Data1,Data2)) 

    def OnButton6Button(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        GlobalStr="".join((GlobalStr,"6"))
        self.textCtrl1.SetValue(GlobalStr)
        if Flag:
            Data2=GlobalStr
        else:
            Data1=GlobalStr
        print ("Data1:%s;Data2:%s" %(Data1,Data2)) 

    def OnButtondivButton(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        if Flag:
            Flag=0            
            
        #elif Flag_YunSuan :
        #    Flag=1 
        #    Data1=Data2
            #Data2=GlobalStr
        else :
            Flag=1
        YunSuan="/"       
        GlobalStr=""
        self.textCtrl1.SetValue("")
        print ("Data1:%s;Data2:%s" %(Data1,Data2))
        print 

    def OnButtondaoButton(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        if Flag:
            Flag=0
            Temp=int(Data2)
            
        #elif Flag_YunSuan :
        #    Flag=1 
        #    Data1=Data2
            #Data2=GlobalStr
        else :
            Flag=1
            Temp=int(Data1)
        #YunSuan="sqr"       
        GlobalStr=""
        
        Temp=1/Temp
        self.textCtrl1.SetValue(str(Temp))
        print ("Data1:%s;Data2:%s" %(Data1,Data2))
        print 

    def OnButton7Button(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        GlobalStr="".join((GlobalStr,"7"))
        self.textCtrl1.SetValue(GlobalStr)
        if Flag:
            Data2=GlobalStr
        else:
            Data1=GlobalStr
        print ("Data1:%s;Data2:%s" %(Data1,Data2)) 

    def OnButton8Button(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        GlobalStr="".join((GlobalStr,"8"))
        self.textCtrl1.SetValue(GlobalStr)
        if Flag:
            Data2=GlobalStr
        else:
            Data1=GlobalStr
        print ("Data1:%s;Data2:%s" %(Data1,Data2)) 
        
    def OnButton9Button(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        GlobalStr="".join((GlobalStr,"9"))
        self.textCtrl1.SetValue(GlobalStr)
        if Flag:
            Data2=GlobalStr
        else:
            Data1=GlobalStr
        print ("Data1:%s;Data2:%s" %(Data1,Data2)) 

    def OnButtondecButton(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        if Flag:
            Flag=0            
            
        #elif Flag_YunSuan :
        #    Flag=1 
        #    Data1=Data2
            #Data2=GlobalStr
        else :
            Flag=1
        YunSuan="-"       
        GlobalStr=""
        self.textCtrl1.SetValue("")
        print ("Data1:%s;Data2:%s" %(Data1,Data2))
        print 
    def OnButtonpercentButton(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        if Flag:
            Flag=0            
            
        #elif Flag_YunSuan :
        #    Flag=1 
        #    Data1=Data2
            #Data2=GlobalStr
        else :
            Flag=1
        YunSuan="%"       
        GlobalStr=""
        self.textCtrl1.SetValue("")
        print ("Data1:%s;Data2:%s" %(Data1,Data2))
        print 

    def OnButton0Button(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        GlobalStr="".join((GlobalStr,"0"))
        self.textCtrl1.SetValue(GlobalStr)
        if Flag:
            Data2=GlobalStr
        else:
            Data1=GlobalStr
            
        print ("Data1:%s;Data2:%s" %(Data1,Data2)) 

    def OnButtonPosNagButton(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        if re.search("-",GlobalStr):
            Last=len(GlobalStr)                       
            GlobalStr=GlobalStr[1:Last]
            self.textCtrl1.SetValue(GlobalStr)
        else :
            GlobalStr="".join(("-",GlobalStr))
            self.textCtrl1.SetValue(GlobalStr)
        if Flag:
            Data2=GlobalStr
        else:
            Data1=GlobalStr
        print ("Data1:%s;Data2:%s" %(Data1,Data2)) 

    def OnButtonpotButton(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        GlobalStr="".join((GlobalStr,"."))
        self.textCtrl1.SetValue(GlobalStr)
        
        print ("Data1:%s;Data2:%s" %(Data1,Data2)) 
    def OnButtonaddButton(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        if Flag:
            Flag=0            
            
        #elif Flag_YunSuan :
        #    Flag=1 
        #    Data1=Data2
            #Data2=GlobalStr
        else :
            Flag=1
        YunSuan="+"       
        GlobalStr=""
        self.textCtrl1.SetValue("")
        print ("Data1:%s;Data2:%s" %(Data1,Data2))
        print 
    def OnButtonbackspaceButton(self, event):
        event.Skip()

    def OnButtonceButton(self, event):
        event.Skip()

    def OnButtoncButton(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        self.textCtrl1.SetValue("")
        GlobalStr=""

    def OnButtonequButton(self, event):
        global GlobalStr,Data1,Data2,Flag,YunSuan
        Flag=0
        Flag_YunSuan=1
        print ("Data1:%s;Data2:%s" % (Data1,Data2))
        if Data1:
            Data1=int(Data1)
        if Data2:
            Data2=int(Data2)
                
        if YunSuan == "+":
            Temp=Data1 + Data2
            self.textCtrl1.SetValue(str(Temp))
            Data1=Temp
            Data2=""
            
        elif YunSuan == "-":
            Temp=Data1 - Data2
            self.textCtrl1.SetValue(str(Temp))
            Data1=Temp
            Data2=""
            
        elif YunSuan == "/":
            Temp=Data1 / Data2
            self.textCtrl1.SetValue(str(Temp))
            Data1=Temp
            Data2=""
        elif YunSuan == "*":
            Temp=Data1 * Data2
            self.textCtrl1.SetValue(str(Temp))
            Data1=Temp
            Data2=""
            
        
        
        print ("Data1:%s;Data2:%s" % (Data1,Data2))
